#include "stdafx.h"
#include "wf_layersremove.h"

#include "pf_graphic.h"



WF_LayersRemove::WF_LayersRemove(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_ActionInterface("Remove Layer", container, graphicView) {}


QAction* WF_LayersRemove::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// tr("&Remove Layer")
    QAction* action = new QAction(tr("Remove Layer"), NULL);
    //action->zetStatusTip(tr("Remove Layer"));
	action->setIcon(QIcon(":/ui/layerremove.png"));
    return action;
}


void WF_LayersRemove::trigger() {
    PF_DEBUG->print("PF_ActionLayersRemove::trigger");

    if (graphic!=NULL) {
        PF_Layer* layer =
            PF_DIALOGFACTORY->requestLayerRemovalDialog(graphic->getLayerList());

        /*
              if (layer!=NULL && layer->getName()!="0") {

                  graphic->startUndoCycle();
                  for (PF_Entity* e=graphic->firstEntity(LX_Define::ResolveNone);
                          e!=NULL;
                          e=graphic->nextEntity(LX_Define::ResolveNone)) {

                      if (e->getLayer()!=NULL &&
                              e->getLayer()->getName()==layer->getName()) {

                          e->setUndoState(true);
                          e->setLayer("0");
                          graphic->addUndoable(e);
                      }
                  }


                  graphic->endUndoCycle();
        */

        // Now remove the layer from the layer list:
        graphic->removeLayer(layer);
    }
    finish();
    PF_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
}



void WF_LayersRemove::init(int status) {
    PF_ActionInterface::init(status);
    trigger();
}

// EOF
